package Com.CXSH.Guanwan.config;

/**
 * @className: Restult
 * @description: 统一后台返回格式
 **/
public class Result {
    // 返回的状态码
    private int code;

    // 返回的信息提示
    private String message;

    // 返回的数据
    private Object result;

    private Result() {
    }

    private Result(int code, String message, Object result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    @Deprecated
    public static Result resultError(boolean r){
        if(r){
            return ok();
        }else {
            return error();
        }
    }

    public static Result result(boolean r){
        if(r){
            return ok();
        }else {
            return error();
        }
    }

    public static Result ok(){
        return ok(ResultConstant.OK_MESSAGE,null);
    }

    public static Result ok(Object result){
        return ok(ResultConstant.OK_MESSAGE,result);
    }

    public static Result ok(String message, Object result){
        return new Result(ResultConstant.OK,message,result);
    }

    public static Result error(){
        return error(ResultConstant.ERROR_MESSAGE,null);
    }

    public static Result error(Object result){
        return error(ResultConstant.ERROR_MESSAGE,result);
    }

    public static Result error(String message, Object result){
        return new Result(ResultConstant.ERROR,message,result);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return message;
    }

    public void setMsg(String message) {
        this.message = message;
    }

    public Object getData() {
        return result;
    }

    public void setData(Object result) {
        this.result = result;
    }
}
